Page({
  data: {
    images: [],
    timestamp: '',
    location: ''
  },

  onLoad: function(options) {
    const cachedData = wx.getStorageSync('cachedImages') || [];
    this.setData({
      images: cachedData,
      timestamp: options.timestamp || '未记录时间',
      location: decodeURIComponent(options.location) || '未知位置'
    });

    setTimeout(() => {
      wx.removeStorageSync('cachedImages');
    }, 1000);
  },

  deleteImage: function(e) {
    const index = e.currentTarget.dataset.index;
    const newImages = this.data.images.filter((_, i) => i !== index);
    this.setData({ images: newImages });
  },

  saveToAlbum: function() {
    wx.showLoading({ title: '保存中...' });
    Promise.all(this.data.images.map(url => 
      wx.saveImageToPhotosAlbum({ filePath: url })
    )).then(() => {
      wx.hideLoading();
      wx.showToast({ title: '保存成功', icon: 'success' });
    }).catch(err => {
      wx.hideLoading();
      wx.showToast({ title: '保存失败', icon: 'none' });
    });
  },

  goBack: function() {
    wx.navigateBack();
  }
});